Sistema de Nombrado en Java (JNDI) [Parte I]

El LDAP v3 (RFC 2251) define un notificaci�n no solicitada, un mensaje que es env�ado por un servidor LDAP al cliente sin ninguna provocaci�n por parte del cliente. Una notificaci�n no solicitada est� representada en el JNDI por el inteface UnsolicitedNotification.

Como las notificaciones no solicitadas las env�a el servidor de forma as�ncrona, podemos usar el mismo modelo de eventos usado para recibir notificaciones sobre cambios en el espacio de nombres y en contenidos de objetos. Registramos el inter�s en notificaciones no solicitadas registrando un UnsolicitedNotificationListener con un EventContext o un EventDirContext.

Aqu� tenemos un ejemplo de un UnsolicitedNotificationListener.

public class UnsolListener implements UnsolicitedNotificationListener {
    public void notificationReceived(UnsolicitedNotificationEvent evt) {
        System.out.println("received: " + evt);
    }

    public void namingExceptionThrown(NamingExceptionEvent evt) {
        System.out.println(">>> UnsolListener got an exception");
	    evt.getException().printStackTrace();
    }
}

Abajo tenemos un ejemplo que registra una implementaci�n de UnsolicitedNotificationListener con una fuente de eventos. Observa que s�lo es importante el argumento listener de EventContext.addNamingListener().

Los par�metros name y scope no son importantes para las notificaciones no solicitadas.

// Get the event context for registering the listener
EventContext ctx = (EventContext)
    (new InitialContext(env).lookup("ou=People"));

// Create the listener
NamingListener listener = new UnsolListener();

// Register the listener with the context (all targets equivalent)
ctx.addNamingListener("", EventContext.ONELEVEL_SCOPE, listener);

Cuando ejecutamos este programa, necesitamos apuntar a un servidor LDAP que pueda generar notificaciones no solicitadas y provoque que el servidor emita la notificiaci�n. De otra forma despu�s de un minuto, el programa saldr� silenciosamente.

Un oyente que implementa UnsolicitedNotificationListener tambi�n puede implementar otros interfaces NamingListener, como NamespaceChangeListener y ObjectChangeListener.

COMPARTE ESTE ARTÍCULO

COMPARTIR EN FACEBOOK
COMPARTIR EN TWITTER
COMPARTIR EN LINKEDIN
COMPARTIR EN WHATSAPP
SIGUIENTE ARTÍCULO